<?php
require_once "config.php";
require_once "filter.php";
require_once "GoogleAPI.php";
require_once "FacebookAPI.php";
require_once "Connection.php";

session_start();

if(isset($_GET['c']) && isset($_GET['k'])){
	$selected_category = $_GET['c'];
	$selected_key = $_GET['k'];
}
else{
	$selected_category = 0;
	$selected_key = 0;
}

$facebookAPI = new FacebookAPI();
if(isset($_REQUEST['code'])){
  	$user = $facebookAPI->login();
}

$googleAPI = new GoogleAPI();
$topKeywords = $googleAPI->getTopSearchKeywords();

if(isset($_SESSION['LOGIN_INFO']['id'])){
	$conn = new Connection();
	$categories = $conn->fetchCategory($_SESSION['LOGIN_INFO']['id']);
	$categories = urldecode($categories);
	$categories = json_decode($categories,true);
	$sub_category = $conn->fetchSubCategory($_SESSION['LOGIN_INFO']['id']);
	$sub_category = urldecode($sub_category);
	$sub_category = json_decode($sub_category,true);
	
}
//echo "<pre>";print_r($sub_category);echo "</pre>";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-TW" lang="zh-TW">

<head>
  <title>ULikeWall</title>

  <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />  
  <meta name="keywords" content="ULikeWall" />
  <meta name="description" content="ULikeWall" />
  <meta property="og:title" content="ULikeWall"/>
  <meta property="og:url" content="www.ulikewall.com"/>
  <meta property="og:site_name" content="ULikeWall"/>
  <meta property="og:description" content="ULikeWall"/>
  
  <link rel="stylesheet" type="text/css" href="styles/css/html.css" media="screen, projection, tv " />
  <link rel="stylesheet" type="text/css" href="styles/css/layout.css" media="screen, projection, tv" />
  <link rel="stylesheet" type="text/css" href="styles/css/print.css" media="print" />
  <link rel="stylesheet" type="text/css" href="styles/css/jquery.fancybox-1.3.1.css"  />
  <script src="styles/js/jquery.js" type="text/javascript"></script>
  <script src="styles/js/ajax.js" type="text/javascript"></script>
  <script src="styles/js/ulikewall.js" type="text/javascript"></script>
  <script src="styles/js/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script>
  <script src="https://www.google.com/jsapi?key=<?php echo GOOGLE_API_KEY;?>" type="text/javascript"></script>
  <script type="text/javascript">
  	$(document).ready(function(){
		//getRSSByCategory('<?php echo $selected_category?>','<?php echo $selected_key?>',false,0);
        getLocalContent($("#localContent>li").children());
		
        if ($("#editSubscription").length > 0) {
            
			//$.fancybox.showActivity();
            $("#editSubscription").fancybox({
                ajax: {
                    type: "POST"
                },
				'onClosed':function() {
					location.reload();
				},
				'scrolling': 'auto',
				'opacity':true,
				'overlayOpacity':0.7,
				'titleShow':false,
				'overlayColor':'#000',
				'showActivity':true,
				'autoScale':true
            });

        }
		
		if ($("#addSubscription").length > 0) {
            
			//$.fancybox.showActivity();
            $("#addSubscription").fancybox({
                ajax: {
                    type: "POST"
                },
				'onClosed':function() {
					location.reload();
				},
				'scrolling': 'auto',
				'opacity':true,
				'overlayOpacity':0.7,
				'titleShow':false,
				'overlayColor':'#000',
				'showActivity':true,
				'autoScale':true
            });
			$('#fancybox-inner').width(400);


        }
	});
  	
	function showList(){
		//manageCategory('<?php echo $selected_category?>');
	}
	
  </script>

</head>


<body onload="showList();">

<!-- CONTENT: Holds all site content except for the footer.  This is what causes the footer to stick to the bottom -->
<div id="content">
  <!-- HEADER: Holds title, subtitle and header images -->
  <div id="header">

    <div id="title">
    	<!--
      <h1>U Like Wall</h1>
      <h2>in the city</h2>
	  -->
    </div>

    <img src="styles/images/bg/balloons.gif" alt="balloons" class="balloons" />
    <img src="styles/images/bg/header_left.jpg" alt="left slice" class="left" />
    <img src="styles/images/bg/header_right.jpg" alt="right slice" class="right" />

  </div>



   <!-- MAIN MENU: Top horizontal menu of the site.  Use class="here" to turn the current page tab on -->
  <?php require_once "include/tags.php";?>


  <!-- PAGE CONTENT BEGINS: This is where you would define the columns (number, width and alignment) -->
  <div id="page">

    <div class="width25 floatLeft leftColumn">

      <!--<h1>Help</h1>-->

      <ul class="sideMenu">
      	<li class="here">
			<span style="cursor: pointer; cursor: hand;" onclick="manageCategory('localContent')">首頁</span>
				<ul style="display:none;" id="localContent">
					<li><a href="#" original="files/html/宅男教室之-綜合所得稅報稅三部曲.html" class="localContentLink">宅男教室之-綜合所得稅報稅三部曲</a></li>
				</ul>
		</li>
		<?php
		if(!empty($categories)){
			foreach($categories as $cat_key=>$cat_title){			
		?>
		        <li class="here">
		          <span style="cursor: pointer; cursor: hand;" onclick="manageCategory('<?php echo $cat_key; ?>')"><?php echo $cat_title; ?></span>
		          <ul style="display:none;" id="<?php echo $cat_key; ?>">
		          	<?php
					if(!empty($sub_category[$cat_key])){
						foreach($sub_category[$cat_key] as $key=>$term){
							echo '<li><a href="index.php?c='.$cat_key.'&k='.$key.'" title="'.$cat_key.'" >';
								if(@$sub_category[$selected_category][$selected_key]['title'] != $term['title']){
									echo $term['title'];
								}
								else{
									echo '<span class="nowCategory">'.$term['title'].'</span>';
								}
							echo '</a></li>';																				
						}
					}
					?>
		          </ul>
		        </li>
		<?php
			}
		}else{
			echo '<li class="here">尚無訂閱</li>';
		}
		?>
        
		<!--
        <li><a href="http://fullahead.org" title="Goto Fullahead">Fullahead</a></li>
        <li><a href="http://threetree.net" title="Goto Threetree">ThreeTree</a></li>
		-->
      </ul>

	<!--
      <p>
        If you still have questions after reading this, feel free to <a href="http://fullahead.org/contact.html" title="Fullahead contact form">contact me</a>.  I can't promise I'll answer you right away, but I will get back to you.
      </p>
	-->
	<ul class="sideMenu">
	<li class="here">
		<form id="dummy" action="moreResults.php" method="get" target="_blank">
          <p>
            <h5>想看更多？</h5>
            <input type="text" name="q" style="width:65%;margin-right:4px;"/><input type="submit" value="搜尋" class="button"/>
          </p>          
        </form>
	</li>
	</ul>
	
	<blockquote class="topkeyword">
	<ul class="sideMenuTopKeyword">
		<h3>熱門搜尋關鍵字</h3>
			<?php
			foreach($topKeywords as $item=>$detail){
				if(!isset($detail->prev_rank)){
					echo '<li class="up">';
				}
				elseif($detail->rank <= $detail->prev_rank){
					echo '<li class="up">';
				}
				else echo '<li class="down">';
								
				//echo '<span>'.$detail->rank.'.</span>';			
				echo '<span><a style="font-size:1.2em;" target="_blank" href="moreResults.php?q='.urlencode($detail->query).'">'.$detail->query.'</a>';
					echo '<a style="cursor:pointer;"onclick="manageDescr(\'topKeyword'.$detail->rank.'\');">+</a>';
				echo '</span>';								
				echo '</li>';
				echo '<p id="topKeyword'.$detail->rank.'">'.$detail->snippet.'</p>';
				if($detail->rank >= 15) break;
			}
			?>
	</ul>
	</blockquote>
	
	
	<div style="text-align:center;">	
	<!-- Histats.com  START  (standard)-->
	<!--
	<script type="text/javascript">document.write(unescape("%3Cscript src=%27http://s10.histats.com/js15.js%27 type=%27text/javascript%27%3E%3C/script%3E"));</script>
	<a href="http://www.histats.com" target="_blank" title="web counter" ><script  type="text/javascript" >
	try {Histats.start(1,1243262,4,273,112,35,"00011000");
	Histats.track_hits();} catch(err){};
	</script></a>
	<noscript><a href="http://www.histats.com" target="_blank"><img  src="http://sstatic1.histats.com/0.gif?1243262&101" alt="web counter" border="0"></a></noscript>
	-->
	<!-- Histats.com  END  -->
	
	</div>
	
	
    </div>
    <div class="width75 floatRight">
      <div id="main_info"></div>
	  <div class="alignCenter" id="loading_img" style="display:none;" ><img src="styles/images/ui-anim_basic_16x16.gif"/></div>
    </div>

  </div>

</div>


<!-- FOOTER: Site footer for links, copyright, etc. -->
<div id="footer">

  <div id="width">
  	copyright &copy; ULikeWall
	<!--
    <span class="floatLeft">
    	
      design <a href="http://fullahead.org" title="Goto Fullahead">Fullahead</a> <span class="grey">|</span>
      valid <a href="http://validator.w3.org/check?uri=referer" title="Validate XHTML">XHTML</a> <span class="grey">|</span>
      should be valid <a href="http://jigsaw.w3.org/css-validator" title="Validate CSS">CSS</a>
	 
	  
    </span>

    <span class="floatRight">
      <a href="index.html" title="Introduction">intro</a> <span class="grey">|</span>
      <a href="help.html" title="Learn how to use the template">help</a> <span class="grey">|</span>
      <a href="tags.html" title="View the styled tags">tags</a> <span class="grey">|</span>
      <a href="print.html" title="View the print layout">print</a> <span class="grey">|</span>
      <a href="http://fullahead.org/contact.html" title="Get in touch">mail</a>
    </span>
	-->
  </div>

</div>

</body>

</html>